﻿using System.Collections.Generic;
using System.ComponentModel;
using CrateMayhem.Common.Commanding;

namespace CrateMayhem.Common.ViewModel
{
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private readonly List<DelegateCommand> commands = new List<DelegateCommand>();

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected DelegateCommand RegisterCommand(DelegateCommand command)
        {
            commands.Add(command);
            return command;
        }

        protected void RaiseCanExecuteChanged()
        {
            foreach (var command in commands)
            {
                command.RaiseCanExecuteChanged();
            }
        }
    }
}